#!/usr/bin/env python

# bt_main.py - A pygtk2 application to demonstrate bluetooth functions
#
# Version 0.1
#
# Authors: Erin Yueh <erinyueh@gmail.com>
#
# Copyright (c) 2008 Erin Yueh
#
# bt_main.py is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# browse_device.py is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.


import gtk, gobject
import browse_device, pin, send_file
import bt_adapter 

POWER_STATE = ('OFF', 'ON')

class bt_main(object):

    def power_status_cb(self,widget):
        print 'power_status_cb', widget

        self.curr_status = self.bluetooth_adapter.getPower()
        if self.curr_status == 1:
            self.bluetooth_adapter.setPower(False)
            self.power_button.set_label("Power Status: OFF")
            print 'set Power OFF'
        elif self.curr_status == 0:
            self.bluetooth_adapter.setPower(True)
            self.power_button.set_label("Power Status: ON")
            print 'set Power ON'


    def browse_device_cb(self,widget):
        print 'browse_device_cb', widget
        self.browse = browse_device.BrowseDevice(self)


    def send_file_cb(self,widget):
        print 'send_file_cb', widget
        send_file.FileSelectionExample(self)


    def preferences_cb(self,widget):
        print 'send_preferences_cb', widget

    def __init__(self):
        # build bluetooth adapter
        self.bluetooth_adapter = bt_adapter.BluetoothAdapter(self)

        # Create the user interface
        self.win = gtk.Window()
        self.win.connect('delete-event', gtk.main_quit)

        self.vbox = gtk.VBox()
        self.win.add (self.vbox)
        self.hbox = gtk.HBox()
        self.vbox.pack_start (self.hbox)

        # Bluetooth Power
        #status = bt_iface.GetPower()
        status = 1
        self.power_button = gtk.Button()
        self.power_button.set_label('Power Status: '+ POWER_STATE[status])
        self.power_button.connect ("clicked", self.power_status_cb)
        self.vbox.pack_start (self.power_button)

        # Browse Devices
        self.device_button = gtk.Button()
        self.device_button.set_label('Browse Devices')
        self.device_button.connect ("clicked", self.browse_device_cb)
        self.vbox.pack_start (self.device_button)

        # Send File
        self.file_button = gtk.Button()
        self.file_button.set_label('Send File')
        self.file_button.connect ("clicked", self.send_file_cb)
        self.vbox.pack_start (self.file_button)

        # preferences
        self.pref_button = gtk.Button()
        self.pref_button.set_label('Perferences')
        self.pref_button.connect ("clicked", self.preferences_cb)
        self.vbox.pack_start (self.pref_button)

        # Show all widgets and start the main loop
        self.win.show_all()

def main():
    gtk.main()

if __name__ == "__main__":
    bt_main()
    main()

